﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Services;
using Web.Views.DataManage.Models;
using ePlanet.SingleWell.Models;
using ePlanet.SingleWell.DataAccess;
using System.Web.Script.Serialization;
using System.Data;
using ePlanet.Entities;

namespace Web.Views.DataManage
{
    /// <summary>
    /// SingleWellDataManageHandler 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SingleWellDataManageHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.ContentType = "text/plain";
                int intPageSize = int.Parse(context.Request["rows"].ToString());
                int intCurrentPage = int.Parse(context.Request["page"].ToString());
                List<SingleWellEntity> models = new List<SingleWellEntity>();
                SingleWellDAl dal = new SingleWellDAl();
                SingleWellModel.SINGLEWELLDataTable table = dal.GetSingleWellDatas();
                foreach (DataRow row in table.Rows)
                {
                    SingleWellModel.SINGLEWELLRow singleRow = row as SingleWellModel.SINGLEWELLRow;
                    if (singleRow != null)
                    {
                        SingleWellEntity entity = SingleWellEntityHelper.RowToEntity(singleRow);
                        models.Add(entity);
                    }
                }
                string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(new { total = models.Count, rows = models });
                context.Response.Write(jsonStr);
                context.Response.End();
            }
            catch(Exception ex) 
            {
                throw ex;
            } 
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}